﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Furion.DatabaseAccessor;
using Microsoft.AspNetCore.Mvc;
using YShop.Application.Contracts.Shop;
using YShop.Core.Entites;
using Mapster;
using YShop.Core.Managers.Caches;

namespace YShop.Application.Shop
{
    /// <summary>
    /// 商品
    /// </summary>
    [ApiDescriptionSettings("Shop")]
    public class ProductService : CrudMasterSlave1Service<Product,ProductDetail, ProductDto, ProductDto, PageSearchDto, ProductDto, ProductDto>, IBaseService
    {
        private readonly IRepository<Product> _repository;
        private readonly IRepository<ProductDetail> _detailRepository;
        private readonly CacheManager _cacheManager;

        public override List<Product> EntitiesCache => _cacheManager.GetOrCreate(CacheKeys.Products, _ => 
        {
            return _repository.Include(s => s.Details, false).ToList();
        });
        public override string EntitiesCacheKey => CacheKeys.Products;

        public ProductService(IRepository<Product> repository, IRepository<ProductDetail> detailRepository,CacheManager cacheManager) 
            : base(repository, detailRepository)
        {
            _repository = repository;
            _detailRepository = detailRepository;
            _cacheManager = cacheManager;
        }

    }

}
